try:
    f = open("../resources/file.txt")
    data = f.read()
    print(data)
except FileNotFoundError as e:
    print("文件不存在")
except IOError as e:
    print("IO错误")
except Exception as e:
    print("未知错误")
finally:
    # 关闭文件
    if f:
        f.close()

print("=" * 50)
try:
    # 文件处理时可以使用 with 语句，with 语句会自动处理文件打开和关闭的问题
    with open("../resources/file.txt") as f:
        data = f.read()
        print(data)
except FileNotFoundError as e:
    print("文件不存在")
except IOError as e:
    print("IO错误")
except Exception as e:
    print("未知错误")
